//
//  LPNavController.m
//  彩票
//
//  Created by liupan on 2016/11/29.
//  Copyright © 2016年 liupan. All rights reserved.
//

#import "LPNavController.h"

typedef void(^myblock)();

@interface LPNavController ()
@property (nonatomic,copy)myblock block;
@end

@implementation LPNavController
//当第一次初始化这个类的时候调用,如果有子类会调用多次
+ (void)initialize{
    if (self == [LPNavController class]) {//判断是否是当前类
        //设置导航背景
        UINavigationBar *bar= [UINavigationBar appearance];
        [bar setBackgroundImage:[UIImage imageWithOriginalRenderingimage:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
        NSMutableDictionary *dictionary=[NSMutableDictionary dictionary];
        dictionary[NSFontAttributeName]=[UIFont systemFontOfSize:18];
        dictionary[NSForegroundColorAttributeName]=[UIColor whiteColor];
        [bar setTitleTextAttributes:dictionary];
    }

}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.interactivePopGestureRecognizer.delegate=nil;//清空手势代理
    
}
//拦截push方法，隐藏tabBar
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{

    if (self.viewControllers.count > 0) {//如果push进来不是根控制器
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"返回" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button setImage:[UIImage imageNamed:@"NavBack"] forState:UIControlStateNormal];
        [button sizeToFit];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);//左边内边距切掉10
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
        viewController.hidesBottomBarWhenPushed=YES;//隐藏tabBar
    }
    // 这句super的push要放在后面, 让viewController可以覆盖上面设置的leftBarButtonItem
    [super pushViewController:viewController animated:YES];//根控制器
}
//返回按钮
- (void)back{

    [self popViewControllerAnimated:YES];
}
@end
